{extend name="public/base"/} {block name="body"}
<style>
    .mui-row.mui-fullscreen>[class*="mui-col-"] {
        height: 100%;
    }

    .mui-col-xs-3,
    .mui-col-xs-9 {
        overflow-y: auto;
        height: 100%;
    }

    .mui-segmented-control .mui-control-item {
        line-height: 50px;
        width: 100%;
    }

    .mui-control-content {
        display: block;
    }

    .mui-segmented-control.mui-segmented-control-inverted .mui-control-item.mui-active {
        background-color: #fff;
    }
    .mui-toast-container {
        bottom: 50%;
        z-index: 999999999999999999;
    }
    .mui-btn-block{
      padding: 5px;
      border: 1px solid #ccc !important;
      margin: 5px;
      -webkit-appearance: none;
    }
    .active .mui-icon{
      display: block !important;
    }
    .submitbuttonqx {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 2.876712rem;
        background-color: red;
        color: #fff;
        text-align: center;
        text-decoration: none;
        font-size: 0.410959rem;
        font-weight: bold;
        line-height: 1.315068rem;
    }
    .nextday{
      font-size: 12px;
position: absolute;
top: 23px;
left: 25%;
color: red;
    }
</style>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
<header class="mui-bar mui-bar-nav" style="z-index:7">
	
</header>
<div class="mui-content" style="    margin-bottom:60px;">
  <div  class="checkout-section" >
      <section class="cart-address" >
          <div class="address-item"   onclick='window.location.href = "{:url('index/address/index')}"'   {empty name="$address['sex']"}style="display: none;"{/empty}>
              <h2 class="address-name" > <b >{$address.name}</b>
              	 <span >{eq name="$address['sex']" value='1'}先生{else /}女士{/eq}</span> 
              	 <span >{$address.tel}</span> 
              	 </h2>
              	 <p class="address-detail" >微信号:{$address.wx_number} </p>  
              <p class="address-detail" >{$address.address}-{$address.house_number}</p> <span class="mui-icon mui-icon-arrowright"></span> 
               
               </div>
          <div class="address-item" onclick='window.location.href = "{:url('index/address/addwxopen')}"' {notempty name="$address['sex']"}style="display: none;"{/notempty} > 请添加一个收货地址 <span class="mui-icon mui-icon-arrowright"></span> </div>
      </section>

  <br />
  <section class="cart-group checkout-section">
      <ul class="foodlist" style="    margin: 0;">
          {volist name="cartlist" id="vo"}
            <li> <span class="cellname">{$vo.good_name}</span> <span class="cellquantity">x&nbsp;{$vo.num}</span> <span class="celltotal">¥{$vo['num']*$vo['good_price']}</span> </li>
          {/volist}
          {empty name="cartlist"}
            <script>

              window.location.href = "{:url('index/index/stindex')}"

            </script>
          {/empty}
      </ul>
    <!-- <div class="fee" >
        <div >配送费(约{$address.disparity}公里)</div>
        <div id="freight" >¥{$yunfei}</div>
    </div> 
     <div class="fee" >
        <div >配送费</div>
        <div id="freight" >¥{$yunfei}</div>
    </div>-->
  <!--
    <div class="fee" >
        <div >余额支付</div>
        <div >¥{$Request.session.user.balance}</div>
    </div>-->
    <!-- {eq name=":config('is_freight_promot')" value="1"}

    <div class="fee" >
          <div >运费补贴 (活动商品没有运费补贴)<br />(每消费{:config('freight_promot_meet_price')}元,运费补贴{:config('freight_promot_reduce_price')}}元,补贴最高等于运费)</div>
          <div class="fbt">-¥{0}</div>
    </div>
    {/eq} -->

    <!-- <div class="fee" >

        {eq name="isMember" value="1"}
        <div>会员折扣 (活动商品没有会员折扣)</div>
        <div>  {:config('member_discount')*10}折</div>
        {else /}
        <div>
          <a href="{:url('index/user/info')}">注册会员</a><span>(会员注册后享受9.7折折扣)</span>
        </div>
        {/eq}
    </div> -->
      <div class="total">
          <div> <span>总计 <span id="zj">¥{$cartCountprice+$yunfei}</span>
            <!-- 运费补贴 <span class="fbt">¥{:getSubsidy($freight_art_price, $address['freight'], $eventsGoods)}</span>  -->
            余额 ¥{$Request.session.user.balance}</span> &nbsp;&nbsp; </div>
          <span>实付<span style="color:red;" id="sf" data-sf="{$cartCountprice+$yunfei-$Request.session.user.balance}"> ¥{$cartCountprice+$yunfei-$Request.session.user.balance}</span></span>
      </div>


  </section>


<!-- 
  <section class="checkout-section">
    <div class="cart-item fee" id="pstime" style="    margin: 0;" >
      <span>配送时间</span>
       <span class="cartitem-right" id="pssj">
         <i style="    font-style: normal;">
           {empty name="Think.cookie.deliverytime"}
             {eq name='Think.cookie.shopindex' value="index/index/mailindex"}
                明日发货
             {else/}
               请选择配送时间
             {/eq}
           {else /}
             {$Think.cookie.deliverytime|setDeliverytimeText}
           {/empty}
         </i>

         {eq name='Think.cookie.shopindex' value="index/index/mailindex"}
            <input type="hidden" name="deliverytime"  value='明日发货'  />
         {else/}
           <input type="hidden" name="deliverytime"  value="{$Think.cookie.deliverytime|setDeliverytimeText}"  />
         {/eq}
         <span class="mui-icon mui-icon-arrowright"></span>
       </span>
    </div>
  </section>-->
    <form  method="post"  action="{:url('index/order/add')}">
    	
   
 
         
      <section class="checkout-section">
      <div class="mui-input-row" style="margin: 10px 5px;">
      	<textarea id="textarea" name="remark" rows="5" placeholder="配送说明"></textarea>
      					
      				</div>
      </section>
    </form>

  </div>
  <script id="tpl2" type="text/html">
        <div class="select-time-box">
          <style>.wd50{width:50%!important;}</style>
          {literal}
          {{if date1}}

            <dl class="wd50"  id="jtdd"> <dt>{{date1}}<span>{{name1}}</span></dt>
                {{each list as value i}}
                  <dd class="allow"   data-start="{{value.start_time}}"  data-text="{{date1}}日{{value.start_time}}-{{value.end_time}}送达" data-val="{{date1}},{{value.start_time}}-{{value.end_time}}">
                  	 <label for="radio-choice-0">{{value.start_time}}-{{value.end_time}}</label> </dd>
                {{/each}}
            </dl>
            {{else}}
              <style>.wd50{width:100%!important;}</style>
            {{/if}}
           {/literal}

 {literal}
            <dl  class="wd50" style="position:relative"> <dt >{{date2}}<span>{{name2}}</span>
{{ if nextDis < 1 && nextDis > 0}}
<p class='nextday'>第二天配送{{nextDis}}折</p>
{{/if}}
            </dt>
            	 {{if type2==2}}

            	<dd class="allow" data-text="{{date2}}日10:00-13:00送达" data-val="{{date2}},10:00-13:00">
                  	<label for="radio-choice-0">10:30-13:00</label> </dd>
                  	{{/if}}
                {{each list as value i}}
                  <dd class="allow" data-text="{{date2}}日{{value.start_time}}-{{value.end_time}}送达" data-val="{{date2}},{{value.start_time}}-{{value.end_time}}">
                  	<label for="radio-choice-0">{{value.start_time}}-{{value.end_time}} </label> </dd>
                {{/each}}
            </dl>
            {/literal}
        </div>
  </script>


  <div class="select-time-mask" onclick="hideDeliveryTime()" style="display: none;"></div>
  <div class="select-time-wrap" id="select-model-01" style="display: none;"></div>

  <nav class="mui-bar mui-bar-tab" style="   border-bottom: none;  background-color: #3d3d3f; ">
      <span style="    color: #fff;font-size: .48rem;line-height: 1.273333rem;padding-left: .266667rem;">待支付 <span id="dzf" style="color:red"></span></span>


      {eq name="$zhichi" value='1'}
      <a href="javascript:" class="submitbutton jspsxd"  style="right: 2.876712rem;">确定下单</a>

      <a  class="submitbuttonqx qxdd" data-url="{:url('index/index/stindex')}" >取消订单</a>
      {/eq}
      {eq name="$zhichi" value='2'}
       <a href="javascript:" class="submitbutton jspsxd"  style="right: 2.876712rem;">确定下单</a>

      <a  class="submitbuttonqx qxdd" data-url="{:url('index/index/stindex')}" >取消订单</a>
      
      <!--<a href="javascript:" class="submitbutton " style="    width: 100%;">目前及时配送只支持白云区和观山湖区</a>-->
      
      {/eq}
  </nav>

</div>

{/block}
{block name="script"}

  <script type="text/javascript">
    $(function(){

      //初始化送货方式改变价格
      var wayid =  "{$Think.cookie.way}"
      if(wayid){
        changeprice(wayid)
      }


    //确定下单
    $('.jspsxd').on('tap', function(){
    	
    	//送货时间
      //var deliverytime = $.trim($('[name="deliverytime"]').val())
      
      //if(!deliverytime){
       // mui.toast('请选择送货时间！')
      //  return;
    //  }
      
      //window.location.href = "{:url('index/order/add')}"
      $('form').submit()
    })
    $('.qxdd').on('tap', function(){
     var url = $(this).attr('data-url')
     var btnArray = ['否', '是'];
     mui.confirm('您确定要删除该订单吗？', '删除订单', btnArray, function(e) {
       if (e.index == 1) {
           $.post("{:url('index/cart/clear')}", {}, function(data) {
               mui.toast('删除成功！')
               setTimeout(function() {
                 window.location.href= url
               }, 2000);
           }, "json");

       } else {
         return ;
       }
     })
    })

    $('#payment').on('tap', function(){
        $('.paylist').addClass('open');
        $('.paylist').next().addClass('open');
    })
    $('#coupon-item').on('tap', function(){
        window.location.href = "{:url('index/coupon/index')}"
    })
    $('.mask').on('tap', function(){
      $(this).removeClass('open')
      $('.paylist').removeClass('open')
    })
    $('.paylist-item').on('tap', function(){
      var val = $(this).text(),payway = $(this).attr('data-payway')
      $('#paywaytext').text(val)
      $('.paylist').next().removeClass('open')
      $('.paylist').removeClass('open')
      $(this).addClass('active').siblings().removeClass('active')
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'pay', 'val': payway}, function(json, textStatus) {});
    })

    })

    $('[name="way"]').on('tap', function(){
      var val = $(this).val()
      $.getJSON("{:url('index/cart/changecookie')}", {name: 'way', 'val': val}, function(json, textStatus) {})

      changeprice(val)
    })
    //自提地点
    var yizhan =  "{$yizhan}"
    $.post("{:url('index/address/getArayacak?id='.$yizhan)}", function(data) {
      var html = template('zt', data);
      $('#zt_address').html(html);
    }, "json");

    $(document).on('tap', '#zt_address li', function(){
        var id = $(this).attr('data-ztid')
        $.getJSON("{:url('index/cart/changecookie')}", {name: 'zt_address', 'val': id}, function(json, textStatus) {});
    })
    $('#pstime').on('tap', function(){
              $(".select-time-mask").show(), $(".select-time-wrap").show();

    })
      showDeliveryTime()
    function showDeliveryTime() {
        var data = {}
            data.jt = new Date(),
            data.jm = data.jt.getMonth()+1,
            data.jd = data.jt.getDate();
            data.rq = data.jm+'-'+data.jd;
            data.mt = new Date();
            data.mt.setDate(data.mt.getDate()+1);//当前日期+几天
            data.mm = data.mt.getMonth()+1; // 月
            data.md = data.mt.getDate();    // 日
            data.rq2 = data.mm+'-'+data.md;
            data.ht = new Date();
            data.ht.setDate(data.ht.getDate()+2);//当前日期+几天
            data.hm = data.ht.getMonth()+1; // 月
            data.hd = data.ht.getDate();    // 日
            data.rq3 = data.hm+'-'+data.hd;
        $.post("{:url('index/index/getDeliveryTime')}", function(da) {
            if(da){
              data.list = da;
              if(da[0]['type'] == 1){
                // data.name1 = '明天'
                // data.name2 = '后天'
                // data.date1 = data.rq2
                // data.date2 = data.rq3

                 data.name1 = '今天'
                data.name2 = '明天'
                data.date1 = data.rq
                data.date2 = data.rq2
                data.type2 = 2
              }else {
                 data.name1 = '今天'
                data.name2 = '明天'
                 data.date1 = data.rq
                data.date2 = data.rq2
                data.nextDis = "{:config('nextday_discount')}"


              }
            }
              var html = template('tpl2', data);
              $('.select-time-wrap').html(html);

              if(da[0]['type'] == 0){
                var times = new Date().getHours()+0.1;
                $('#jtdd').find('dd').each(function(){

                  var start = $(this).attr('data-start')
                  if(times>= parseInt(start)){
                    $(this).removeClass('allow').addClass('forbidden').removeAttr('onclick').click(function(){
                         mui.toast("亲，已经过了送货时间，请选择别的时间段~")
                    })
                  }
                })
              }else if(da[0]['type'] == 1){


                var times = new Date().getHours()+0.1;

                $('#jtdd').find('dd').each(function(){

                  //var start = $(this).attr('data-start')
                 var start="13:00";
                  if(times>= parseInt(start)){
                    $(this).removeClass('allow').addClass('forbidden').removeAttr('onclick').click(function(){
                         mui.toast("亲1，已经过了送货时间，请选择别的时间段~")
                    })
                  }
                })


              }



        }, "json");

    }
    $(document).on('tap', '.select-time-box dd.allow',function(){
      var $this = $(this),text = $this.attr('data-text'),val = $this.attr('data-val')
        $('#pssj i').text(text)
        $('#pssj input').val(val)
        $(".select-time-wrap").hide(), $(".select-time-mask").hide()

        $.getJSON("{:url('index/cart/changecookie')}", {name: 'deliverytime', 'val': val}, function(json, textStatus) {
   		 });
    })
    function hideDeliveryTime() {
        $(".select-time-mask").hide(), $(".select-time-wrap").hide()
    }

    function changeprice(way_id){

      if(way_id==1){
        $('.fbt').text("-¥{0}")
       // $('#freight').text("¥{$yunfei|default='0'}")
        $('#freight').text("¥{$yunfei|default='0'}")
        $('#zj').text("¥{$cartCountprice+$yunfei-0}");
        $('#sf').text("¥{$cartCountprice+$yunfei-0-$Request.session.user.balance}");
        preferential("{$cartCountprice+$yunfei-0-$Request.session.user.balance}")
        $('#zt_address').hide();
      }else{
          //除去运费、运费补贴、计算总价
          $('#freight').text('¥0')
          $('.fbt').text('-¥0')
          $('#zj').text("¥{$cartCountprice}");
          $('#sf').text("¥{$cartCountprice-$Request.session.user.balance}");



          preferential("{$cartCountprice-$Request.session.user.balance}")


          $('#zt_address').show();
      }
    }
    function  preferential(sf){

      var yhj = "{$Think.cookie.couponlist_id|get_table_field="id","price","CouponList"}"
      if(yhj){
        var dzf =sf-parseInt(yhj)
      }else{
        dzf =sf

        yhj = 0
      }
      dzf = parseFloat(dzf).toFixed(2)


      $('#dzf').text('¥'+dzf)

      if(sf<0){
        var ye = parseFloat("{$Request.session.user.balance}")+parseFloat(sf)-parseFloat(yhj)
        ye = ye.toFixed(2)
        $('#sf').text('余额支付'+ye)
        $('#dzf').text('余额支付'+ye)

        $('#paywaytext').text('余额支付')
        $('.paylist').remove();
      }

    }


  </script>
{/block}
